package com.fetaphon.blelibrary.entity.data;

import com.fetaphon.blelibrary.utils.ByteUtils;

/**
 * BMS硬件参数
 */
public class BmsHvParams {

    private int macLen; //蓝牙地址长度
    private String mac; //蓝牙地址
    private int iCCIDLen; //ICCID长度
    private String iCCID; //ICCID
    private int bmsNoLen; //BMS序列号长度
    private String bmsNo; //BMS序列号
    private int deviceIdLen; //设备ID长度
    private String deviceId; //设备ID
    private int bmsFVLen; //BMS固件版本长度
    private String bmsFV; //BMS固件版本
    private int bmsHVLen; //BMS硬件版本长度
    private String bmsHV; //BMS硬件版本

    public BmsHvParams(byte[] bytes) {
        try {
            macLen = ByteUtils.byteToInt(ByteUtils.subBytes(bytes, 0, 1));
            byte[] macBytes = ByteUtils.subBytes(bytes, 1, macLen);
            mac = ByteUtils.toString(macBytes);

            iCCIDLen = ByteUtils.byteToInt(ByteUtils.subBytes(bytes, macLen + 1, 1));
            byte[] iCCIDBytes = ByteUtils.subBytes(bytes, macLen + 2, iCCIDLen);
            iCCID = ByteUtils.toString(iCCIDBytes);

            bmsNoLen = ByteUtils.byteToInt(ByteUtils.subBytes(bytes, iCCIDLen + macLen + 2, 1));
            byte[] bmsNoBytes = ByteUtils.subBytes(bytes, iCCIDLen + macLen + 3, bmsNoLen);
            bmsNo = ByteUtils.toString(bmsNoBytes);

            deviceIdLen = ByteUtils.byteToInt(ByteUtils.subBytes(bytes, iCCIDLen + macLen + bmsNoLen + 3, 1));
            byte[] deviceIdBytes = ByteUtils.subBytes(bytes, iCCIDLen + macLen + bmsNoLen + 4, deviceIdLen);
            deviceId = ByteUtils.toString(deviceIdBytes);

            bmsFVLen = ByteUtils.byteToInt(ByteUtils.subBytes(bytes,
                    iCCIDLen + macLen + bmsNoLen + deviceIdLen + 4, 1));
            byte[] bmsFVBytes = ByteUtils.subBytes(bytes, iCCIDLen + macLen + bmsNoLen + deviceIdLen + 5,
                    bmsFVLen);
            bmsFV = ByteUtils.toString(bmsFVBytes);

            bmsHVLen = ByteUtils.byteToInt(ByteUtils.subBytes(bytes,
                    iCCIDLen + macLen + bmsNoLen + deviceIdLen + bmsFVLen + 5, 1));
            byte[] bmsHVBytes = ByteUtils.subBytes(bytes,
                    iCCIDLen + macLen + bmsNoLen + deviceIdLen + bmsFVLen + 6, bmsHVLen);
            bmsHV = ByteUtils.toString(bmsHVBytes);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public int getMacLen() {
        return macLen;
    }

    public String getMac() {
        return mac;
    }

    public int getiCCIDLen() {
        return iCCIDLen;
    }

    public String getiCCID() {
        return iCCID;
    }

    public int getBmsNoLen() {
        return bmsNoLen;
    }

    public String getBmsNo() {
        return bmsNo;
    }

    public int getDeviceIdLen() {
        return deviceIdLen;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public int getBmsFVLen() {
        return bmsFVLen;
    }

    public String getBmsFV() {
        return bmsFV;
    }

    public int getBmsHVLen() {
        return bmsHVLen;
    }

    public String getBmsHV() {
        return bmsHV;
    }
}
